#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;


class Solution {
public:
    int findMaxLength(vector<int>& nums) {
        unordered_map<int, int> hash;
        int n = nums.size();
        int ret = 0;
        hash[0] = -1;
        int sum = 0;
        for (int i = 0; i < n; i++)
        {
            if (nums[i] == 0)
            {
                sum -= 1;
            }
            else
            {
                sum += nums[i];
            }
            if (hash.count(sum))
            {
                ret = max(i - hash[sum], ret);
            }
            else
            {
                hash[sum] = i;
            }
        }
        return ret;
    }
};

int main()
{
    vector<int> ret(10);
    int i = 0;
    int arr[10] = { 0 };
    for (auto &r : arr)
    {
        r = i;
        i++;
        cout << r << " ";
    }
    cout << endl;
    for (auto r : arr)
    {
        cout << r << " ";
    }
    cout << endl;
    for (auto r : ret)
    {
        r = i;
        i++;
        cout << r << " ";
    }
    cout << endl;
    for (auto r : ret)
    {
        cout << r << " ";
    }
    return 0;
}

class Solution {
public:
    int get(const vector<vector<int>>& pre, int m, int n, int x, int y) 
    {
        x = max(min(x, m), 0);
        y = max(min(y, n), 0);
        return pre[x][y];
    }

    vector<vector<int>> matrixBlockSum(vector<vector<int>>& mat, int K) 
    {
        int m = mat.size(), n = mat[0].size();
        vector<vector<int>> P(m + 1, vector<int>(n + 1));
        for (int i = 1; i <= m; ++i) 
        {
            for (int j = 1; j <= n; ++j) 
            {
                P[i][j] = P[i - 1][j] + P[i][j - 1] - P[i - 1][j - 1] + mat[i - 1][j - 1];
            }
        }

        vector<vector<int>> ans(m, vector<int>(n));
        for (int i = 0; i < m; ++i) 
        {
            for (int j = 0; j < n; ++j) 
            {
                ans[i][j] = get(P, m, n, i + K + 1, j + K + 1) - get(P, m, n, i - K, j + K + 1) - get(P, m, n, i + K + 1, j - K) + get(P, m, n, i - K, j - K);
            }
        }
        return ans;
    }
};
